/*
 *
 *  * Copyright (c) iwindplus Technologies Co., Ltd.2024-2030, All rights reserved.
 *
 *
 */

package com.iwindplus.base.redis;

import com.iwindplus.base.redis.domain.property.RedisProperty;
import com.iwindplus.base.redis.aspect.RedisRateLimiterAspect;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Redis限流配置.
 *
 * @author zengdegui
 * @since 2018/9/5
 */
@Slf4j
@Configuration
@EnableConfigurationProperties({RedisProperty.class})
@ConditionalOnProperty(prefix = "spring.redis.rate-limiter", name = "enabled", havingValue = "true", matchIfMissing = true)
public class RedisRateLimiterConfiguration {

    /**
     * 创建 RedisRateLimiterAspect.
     *
     * @return RedisRateLimiterAspect
     */
    @Bean
    public RedisRateLimiterAspect redisRateLimiterAspect() {
        RedisRateLimiterAspect redisRateLimiterAspect = new RedisRateLimiterAspect();
        log.info("RedisRateLimiterAspect={}", redisRateLimiterAspect);
        return redisRateLimiterAspect;
    }

}
